import { useCallback } from "react";
import { View, Text } from "@tarojs/components";
import classNames from "classnames";
import "./index.scss";

function isNumber(n: any) {
  return !Number.isNaN(Number(n));
}

export function addUnit(value: string | number): string {
  return isNumber(value) ? `${value}px` : String(value);
}

interface IPros {
  icon: string;
  onClick?: () => void;
  size?: number | string;
  color?: string;
  className?: string;
  style?: any;
}
const IconFont = (props: IPros) => {
  const { onClick, icon, size = 24, color, style, className } = props;
  const _fn = useCallback(() => {}, []);
  const _onClick = onClick || _fn;

  let fontSize = addUnit(size);

  return (
    <View className={classNames("center", className)} style={style}>
      <Text
        style={{
          color: color,
          fontSize,
        }}
        onClick={_onClick}
        className={`iconfont ${icon} `}
      />
    </View>
  );
};
export default IconFont;
